package com.paygate

import com.alibaba.druid.pool.DruidDataSource
import com.paygate.entity.Trade
import org.ktorm.database.Database
import org.ktorm.entity.sequenceOf
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import javax.annotation.Resource

@Configuration
open class DbConfig {

    @Resource
    lateinit var dataSource: DruidDataSource

    @Bean
    open fun database(): Database = Database.connectWithSpringSupport(dataSource)
}

val Database.trade get() = this.sequenceOf(Trade.table)